package com.example.a2032.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.a2032.R;
import com.hyphenate.chat.EMConversation;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TopAdapter extends RecyclerView.Adapter {

    List<String> stringList;
    int[]resIds;


    public TopAdapter(List<String> stringList, int[]resIds) {
        this.stringList = stringList;
        this.resIds=resIds;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new TopViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_top, parent, false));
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        TopViewHolder settingViewHolder = (TopViewHolder) holder;

        String data = stringList.get(position);
        settingViewHolder.tvTopValue.setText(data);
        settingViewHolder.rlTop.setBackgroundResource(resIds[position]);
        settingViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(itemClickListener!=null)itemClickListener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return stringList.size();
    }

    static class TopViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_topValue)
        TextView tvTopValue;
        @BindView(R.id.rl_top)
        RelativeLayout rlTop;

        public TopViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    onItemClickListener itemClickListener;

    public void setOnItemClickListener(onItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public interface onItemClickListener {
        public void onItemClick(int position);
    }

    public void updateBattery(int batteryValue){
        stringList.set(0,batteryValue+"%");
        notifyDataSetChanged();
    }
    public void updateStep(int stepValue){

        stringList.set(1,stepValue+"");
        notifyDataSetChanged();
    }
    public void updateUnReadMsg(String msgCount){
        stringList.set(2,msgCount);
        notifyDataSetChanged();
    }
}
